﻿using Architecture.API.Application.TraceabilityCommand.ShoppingNameCommand;
using MediatR;
using Traceability.Domain;
using Traceability.Domain.Service.ShoppingNameService;

namespace Architecture.API.Application.TraceabilityCommandHandler.ShoppingNameCommandHandler
{
    /// <summary>
    /// 
    /// </summary>
    public class ShoppingNameCreateCommandHandler : IRequestHandler<ShoppingNameCreateCommand, int>
    {
        /// <summary>
        /// 商品名称服务
        /// </summary>
        protected readonly IShoppingNameService shoppingNameService;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="shoppingNameService">商品名称服务</param>
        public ShoppingNameCreateCommandHandler(IShoppingNameService shoppingNameService)
        {
            this.shoppingNameService = shoppingNameService;
        }

        /// <summary>
        /// 添加商品名称信息
        /// </summary>
        /// <param name="request">请求</param>
        /// <param name="cancellationToken">取消标记</param>
        /// <returns>返回受影响的行数</returns>
        public async Task<int> Handle(ShoppingNameCreateCommand request, CancellationToken cancellationToken)
        {
            return await shoppingNameService.AddShoppingName(new ShoppingName() { ShoppingNames = request.ShoppingName,CreatedBy=request.CreatedBy,CreatedDate=request.CreatedDate });
        }
    }
}
